class Solution:
    def sortInList(self, head: ListNode) -> ListNode:
        p = head
        nums = []

        while p:
            nums.append(p.val)
            p = p.next

        p = head
        nums.sort()

        for i in range(len(nums)):
            p.val = nums[i]
            p = p.next

        return head